/*!
 * FileName: luogu-4942.cpp
 * This Problem is on luogu. The ID of the problem is 4942. 
 * Copyright(c) 2019 Shu_Yu_Mo
 * MIT Licensed
 * Luogu: https://www.luogu.org/space/show?uid=44615
 * Github: https://github.com/oldsuold/
 * Gitee: https://gitee.com/Shu_Yu_Mo/
 * These words were created by an amazing tool written by Shu_Yu_Mo.
 */
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstring>
#include<iostream>
#include<cmath>
#include<vector>
#include<queue>
#include<algorithm>
#define inf 0x7fffffff
using namespace std;
const int _ = 233;
inline int read()
{
    char c = getchar(); int sign = 1; int x = 0;
    while(c > '9' || c < '0') { if(c=='-')sign = -1; c = getchar(); } 
    while(c <= '9' && c >= '0') { x *= 10; x += c - '0'; c = getchar(); }
    return x * sign;
}
int main()
{
	long long a, b;
	int Q = read();
	while(Q--)
	{
		scanf("%lld%lld", &a, &b);
		int ans;
		if((a + b) % 2 == 0) 
			ans = ((a + b) >> 1) % 9 * ((b - a + 1) % 9),
			ans %= 9;
		else
			ans = (((b - a + 1) >> 1) % 9) * ((a + b) % 9),
			ans %= 9;
		printf("%d\n", ans);
	 } 
    return 0;
}
